home *** CD-ROM | disk | FTP | other *** search
- Split-Second Timing
- (PC World October 1986 Star-Dot-Star)
-
- System clock time accurate to 1/100 second is possible with a
- pinch of BASIC and some help from DOS. With such a stopwatch, you
- can, for example, generate far more exact benchmarks. Unfortunately,
- BASIC's reserved variable TIME$ will not return fractions of a second,
- effectively preventing BASIC routines from being time this precisely.
- The machine language subroutine demonstarted by 100THS.BAS enables
- BASIC to read the hundredths-of-a-second values kept by DOS and to
- display them on screen. The program puts the subroutine into memory
- and executes it with BASIC's CALL command.
- The format for calling the subroutine is CALL TIME(hours, minutes,
- seconds, hundredths), where hours, minutes, seconds, and hundredths are
- integer variables to which the corresponding values will be passed.
- You must include a variable for each value, and all four variables must
- be integer type.
-
- 100 '100THS.BAS
- 110 DEF SEG:DEFINT A-Z:DEFSNG T:KEY OFF:CLS
- 120 'Function to add leading zeros to values
- 130 DEF FNA$(X)=RIGHT$("0"+MID$(STR$(X),2,2),2)
- 140 'Place subroutine into memory
- 150 FOR I=1 TO 31
- 160 READ CODE$
- 170 PRG$=PRG$+CHR$(VAL("&H"+CODE$))
- 180 NEXT
- 190 'Call the subroutine
- 200 TPTR=VARPTR(PRG$)
- 210 TIME=PEEK(TPTR+1)+(256*PEEK(TPTR+2))
- 220 CALL TIME(HRS,MIN,SEC,HND)
- 230 'Add leading zeros and display the time
- 240 HR$=FNA$(HRS):MN$=FNA$(MIN)
- 250 SC$=FNA$(SEC):HN$=FNA$(HND)
- 260 LOCATE 12,15,0
- 270 PRINT HR$+":"+MN$+":"+SC$+"."+HN$
- 280 GOTO 200
- 290 'Data for the machine language subroutine
- 300 DATA 55,8b,ec,b4,2c,cd,21,8b,5e,0c,88,2f,8b,5e,0a,88
- 310 DATA 0f,8b,5e,08,88,37,8b,5e,06,88,17,5d,ca,08,00
-
- -----------------------------------------------------------------
- Does Anybody Really Know What Time It Is?
- (PC World The Help Screen December 1986)
-
- A programmer is trying to write a routine in BASIC for a program
- that will permit time operations with greater precision than that
- offered by the reserved variable TIME$. (TIME$ returns values only to
- the nearest minute.) By PEEKing into offsets 1132, 1133, and 1134 of
- segment 0 (DEF SEG = 0), a routine with a precision of about six one-
- hundredths of a minute is possible. Is there a mthod that does not use
- PEEKs and is more precise?
- You can use DOS function 2C hex by MOVing the value 2C into
- register AH (MOV AH,2C) and calling interrupt 21 hex (INT 21) to obtain
- time with a precision of one-hundredth of a second. On return,
- register CH will contain the hours (0 through 23), CL will contain the
- minutes (0 through 59), DH the seconds (0 through 59), and DL the
- hundredths of a second (0 through 99). However, BASIC 2.0's TIMER
- function is easier to use than DOS function 2C and yields results just
- as precise. TIMER is a read-only variable containing the number of
- seconds (to the nearest hundredth) since midnight or system reset.
- Programs using the TIMER function can be compiled with IBM's BASIC
- Compiler 2.00 or with Microsoft's QuickBASIC Compiler.
-